<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/admin/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>用户信息管理界面</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link rel="stylesheet" type="text/css" href="../css/backCss.css">

<link rel="stylesheet" type="text/css" href="../css/list.css">
<script type="text/javascript">

	var allChecked = false;
	//全选/反选操作 	
	function checkAll() { 
		if(allChecked == false){
			allChecked = true;
		}else{
			allChecked = false;
		}
		var checks = document.getElementsByName("checkIDs");
		for(var i = 0;i<checks.length;i++){
			checks[i].checked = allChecked;//ifAll.checked;
		} 
	}
	//双击行的时候选中或撤销选中
	function checkRow(row){ 
		var cell = row.cells[0]; //取得当前行的第一列
		var input = cell.getElementsByTagName("input")[0];//取得列中的第一个input 
		if(input.checked){
			input.checked = "";
		}else{
			input.checked = "checked";
		}
	}
	
	function addUser() { 
		with (document.getElementById("userform")) {
			action="addUser.jsp"; 
			method="post";
			submit();
		}
	}
	//删除用户信息
	function deleteUser(uid){
		if (confirm("确定要删除吗？")) {
			with (document.getElementById("userform")) { 
				action="deleteUser.action?id="+uid; 
				method="post";
				submit();
			}
		}
	} 
	 
	//删除用户控制 
	function deleteListUser() { 
		var checks  = document.getElementsByName("checkIDs");
		var flag = false; 
		 
		for (var i=0; i<checks.length; i++) {
			if (checks[i].checked) {
				flag = true; 
				break;
			}
		}
  
		if (!flag) {
			alert("请选择至少一条需要删除的用户记录！");
			return;
		}
		if (window.confirm("确认删除吗？")) {
			with (document.getElementById("userform")) {
				action="deleteListUser.action";
				method="post";
				submit();
			}
		}
	}

	//首页
	function topPage() {
		if(document.getElementById("currentPage").value==1){ 
			return;
		}
		with (document.getElementById("userform")) {
			document.getElementById("currentPage").value = 1  ; 
			action="listByWherePageUser.action";
			method="post";
			submit();
		} 
	}
	//前一页
	function previousPage() {
		if(document.getElementById("currentPage").value==1){ 
			return;
		}
		with (document.getElementById("userform")) {
			document.getElementById("currentPage").value = ${page.currentPage-1}  ; 
			action="listByWherePageUser.action";
			method="post";
			submit();
		}  
	}	
	//后一页
	function nextPage() {
		var totalPage = ${page.totalPage};
		if(document.getElementById("currentPage").value==totalPage ){  
			return;
		}
		with (document.getElementById("userform")) {
			document.getElementById("currentPage").value = ${page.currentPage+1}  ; 
			action="listByWherePageUser.action";
			method="post";
			submit();
		}  
	}
	//最后一页
	function bottomPage() {
		var totalPage = ${page.totalPage};
		if(document.getElementById("currentPage").value== totalPage ){  
			return;
		}
		with (document.getElementById("userform")) {
			document.getElementById("currentPage").value =  ${page.totalPage}  ; 
			action="listByWherePageUser.action";
			method="post";
			submit();
		}   
	}
	//修改每页显示的数量
	 function changEveryPage(){ 
			with (document.getElementById("userform")) {
			//	document.getElementById("currentPage").value =  1 ;   
				action="listByWherePageUser.action";
				method="post";
				submit();
			}  
	 }

	function listByWhere(){
		with (document.getElementById("userform")) {
			document.getElementById("currentPage").value =  1 ;  
			action="listByWherePageUser.action";
			method="post";
			submit();
		}  
	}
	 
	</script>


</head>
<body>
	<div class="top" align="center">
		<jsp:include page="top.jsp"></jsp:include>
	</div>
	<div class="content" align="center">
		<div align="center" class="main">
			<form action="listByWherePageUser.action" id="userform"
				name="userform" method="post">
				<div align="center">
					<FONT color="red"> ${actionError}<s:actionerror /> </FONT>
				</div>
				<div align="center">
					<h3>用户信息管理列表</h3>
				</div>

				<div class="sort_c" align="center">
					<div align="center">
						用户名：<input type="text" name="user.userID" /> 身份：
						<s:select list="#{'-1':'所有人员','0':'管理员','1':'普通用户'}"
							name="user.identity"></s:select>
						性别：
						<s:select list="#{'-1':'所有人员','1':'男','0':'女'}" name="sex"></s:select>
						<input type="submit" value="条件查询" />
					</div>
					<s:if
						test="#request.userList == null || #request.userList.size() == 0">
						<tr>
							<td colspan="8">
								<div align="center">
									<font color="red"><b>没有查询到相关数据信息</b> </font>
								</div>
							</td>
						</tr>
					</s:if>
					<s:else>
						<div align="center" style="padding-top: 5">
							<table cellspacing="0" cellpadding="0" border="1"
								style="border-collapse:collapse;" bordercolor="black">
								<tr height="25" class="trth">
									<th width="60" onclick="checkAll()">全/反选</th>
									<th>编号</th>
									<th>用户名</th>
									<th>姓名</th>
									<th width="45">性别</th>
									<th width="100">邮箱</th>
									<th width="70">身份</th>
									<th width="180">创建日期</th>
									<th width="130">操作</th>
								</tr>
								<s:iterator id="u" value="userList" status="stu">
									<tr align="center" height="25" class="trtd" id="trtd"
										ondblclick="checkRow(this)">
										<td><input type="checkbox" name="checkIDs" id="checkIDs"
											value="${u.id }" />
										</td>
										<td>${stu.count }</td>
										<td>${u.userID }</td>
										<td>${u.name }</td>
										<td><s:if test="#u.sex == 1">
										男
									</s:if> <s:elseif test="#u.sex == 0">
										女
									</s:elseif></td>
										<td>${u.email }</td>
										<td><s:if test="#u.identity == 0">
										管理员
									</s:if> <s:elseif test="#u.identity == 1">
										普通用户
									</s:elseif></td>
										<td>${u.createDateTime }</td>
										<td>&nbsp; <a href="findUser.action?id=${u.id }">查看</a> <a
											href="editUser.action?id=${u.id }">更新</a> <a
											href="javascript:deleteUser(${u.id })">删除</a> &nbsp;</td>
									</tr>
								</s:iterator>
							</table>
						</div>
					</s:else>
					<div align="center" style="padding-top: 5;">
						当前第<font color="red">${page.currentPage}/${page.totalPage }</font>页&nbsp;
						共<font color="red">${page.totalCount}</font>条记录 每页
						<s:select
							list="#{'10':'10','15':'15','25':'25','35':'35','50':'50','75':'75','100':'100'}"
							name="page.everyPage" onchange="changEveryPage()"></s:select>
						条

						<s:if test="#request.page.hasPrePage">
							<input type="button" name="btnTopPage" id="btnTopPage"
								value="|&lt;&lt; " title="首页" onClick="topPage()">
							<input type="button" name="btnPreviousPage" id="btnPreviousPage"
								value=" &lt;  " title="上页" onClick="previousPage()">

						</s:if>
						<s:else>
							<input type="button" name="btnTopPage" id="btnTopPage"
								value="|&lt;&lt; " title="首页" onClick="topPage()"
								disabled="disabled">
							<input type="button" name="btnPreviousPage" id="btnPreviousPage"
								value=" &lt;  " title="上页" onClick="previousPage()"
								disabled="disabled">
						</s:else>
						<s:if test="#request.page.hasNextPage">
							<input type="button" name="btnNextPage" id="btnNextPage"
								value="  &gt; " title="下页" onClick="nextPage()">
							<input type="button" name="btnBottomPage" id="btnBottomPage"
								value=" &gt;&gt;|" title="尾页" onClick="bottomPage()">
						</s:if>
						<s:else>
							<input type="button" name="btnNextPage" id="btnNextPage"
								value="  &gt; " title="下页" onClick="nextPage()"
								disabled="disabled">
							<input type="button" name="btnBottomPage" id="btnBottomPage"
								value=" &gt;&gt;|" title="尾页" onClick="bottomPage()"
								disabled="disabled">
						</s:else>
						<input type="button" name="btnAdd" id="btnAdd" value="添加"
							onClick="addUser()"> <input type="button" name="btnDel"
							id="btnDel" value="删除" onClick="deleteListUser()"> <input
							type="hidden" name="page.currentPage" id="currentPage"
							value="${page.currentPage}">
					</div>
				</div>
			</form>
		</div>
	</div>
	<div class="foot" align="center">
		<jsp:include page="foot.jsp"></jsp:include>
	</div>
</body>
</html>
